home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / Delphi 3.0 / DATA.Z / DGRDIMPL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-01-30  |  12.3 KB  |  460 lines

  1. unit DGrdImpl;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, DelLib, Grids;
  8.  
  9. type
  10.   TDrawGridX = class(TActiveXControl, IDrawGridX)
  11.   private
  12.     { Private declarations }
  13.     FDelphiControl: TDrawGrid;
  14.     FEvents: IDrawGridXEvents;
  15.     procedure ClickEvent(Sender: TObject);
  16.     procedure ColumnMovedEvent(Sender: TObject; FromIndex, ToIndex: Integer);
  17.     procedure DblClickEvent(Sender: TObject);
  18.     procedure GetEditMaskEvent(Sender: TObject; ACol, ARow: Integer;
  19.       var Value: String);
  20.     procedure GetEditTextEvent(Sender: TObject; ACol, ARow: Integer;
  21.       var Value: String);
  22.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  23.     procedure RowMovedEvent(Sender: TObject; FromIndex, ToIndex: Integer);
  24.     procedure SelectCellEvent(Sender: TObject; Col, Row: Integer;
  25.       var CanSelect: Boolean);
  26.     procedure SetEditTextEvent(Sender: TObject; ACol, ARow: Integer;
  27.       const Value: String);
  28.     procedure TopLeftChangedEvent(Sender: TObject);
  29.   protected
  30.     { Protected declarations }
  31.     procedure InitializeControl; override;
  32.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  33.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  34.     function Get_Col: Integer; safecall;
  35.     function Get_ColCount: Integer; safecall;
  36.     function Get_Color: TColor; safecall;
  37.     function Get_Ctl3D: WordBool; safecall;
  38.     function Get_Cursor: Smallint; safecall;
  39.     function Get_DefaultColWidth: Integer; safecall;
  40.     function Get_DefaultDrawing: WordBool; safecall;
  41.     function Get_DefaultRowHeight: Integer; safecall;
  42.     function Get_DragCursor: Smallint; safecall;
  43.     function Get_EditorMode: WordBool; safecall;
  44.     function Get_Enabled: WordBool; safecall;
  45.     function Get_FixedColor: TColor; safecall;
  46.     function Get_FixedCols: Integer; safecall;
  47.     function Get_FixedRows: Integer; safecall;
  48.     function Get_Font: Font; safecall;
  49.     function Get_GridHeight: Integer; safecall;
  50.     function Get_GridLineWidth: Integer; safecall;
  51.     function Get_GridWidth: Integer; safecall;
  52.     function Get_LeftCol: Integer; safecall;
  53.     function Get_ParentColor: WordBool; safecall;
  54.     function Get_Row: Integer; safecall;
  55.     function Get_RowCount: Integer; safecall;
  56.     function Get_ScrollBars: TxScrollStyle; safecall;
  57.     function Get_TopRow: Integer; safecall;
  58.     function Get_Visible: WordBool; safecall;
  59.     function Get_VisibleColCount: Integer; safecall;
  60.     function Get_VisibleRowCount: Integer; safecall;
  61.     procedure AboutBox; safecall;
  62.     procedure MouseToCell(X, Y: Integer; var ACol, ARow: Integer); safecall;
  63.     procedure Set_Col(Value: Integer); safecall;
  64.     procedure Set_ColCount(Value: Integer); safecall;
  65.     procedure Set_Color(Value: TColor); safecall;
  66.     procedure Set_Ctl3D(Value: WordBool); safecall;
  67.     procedure Set_Cursor(Value: Smallint); safecall;
  68.     procedure Set_DefaultColWidth(Value: Integer); safecall;
  69.     procedure Set_DefaultDrawing(Value: WordBool); safecall;
  70.     procedure Set_DefaultRowHeight(Value: Integer); safecall;
  71.     procedure Set_DragCursor(Value: Smallint); safecall;
  72.     procedure Set_EditorMode(Value: WordBool); safecall;
  73.     procedure Set_Enabled(Value: WordBool); safecall;
  74.     procedure Set_FixedColor(Value: TColor); safecall;
  75.     procedure Set_FixedCols(Value: Integer); safecall;
  76.     procedure Set_FixedRows(Value: Integer); safecall;
  77.     procedure Set_Font(const Value: Font); safecall;
  78.     procedure Set_GridLineWidth(Value: Integer); safecall;
  79.     procedure Set_LeftCol(Value: Integer); safecall;
  80.     procedure Set_ParentColor(Value: WordBool); safecall;
  81.     procedure Set_Row(Value: Integer); safecall;
  82.     procedure Set_RowCount(Value: Integer); safecall;
  83.     procedure Set_ScrollBars(Value: TxScrollStyle); safecall;
  84.     procedure Set_TopRow(Value: Integer); safecall;
  85.     procedure Set_Visible(Value: WordBool); safecall;
  86.   end;
  87.  
  88. implementation
  89. uses DrGridPg; 
  90. { TDrawGridX }
  91.  
  92. procedure TDrawGridX.InitializeControl;
  93. begin
  94.   FDelphiControl := Control as TDrawGrid;
  95.   FDelphiControl.OnClick := ClickEvent;
  96.   FDelphiControl.OnColumnMoved := ColumnMovedEvent;
  97.   FDelphiControl.OnDblClick := DblClickEvent;
  98.   FDelphiControl.OnGetEditMask := GetEditMaskEvent;
  99.   FDelphiControl.OnGetEditText := GetEditTextEvent;
  100.   FDelphiControl.OnKeyPress := KeyPressEvent;
  101.   FDelphiControl.OnRowMoved := RowMovedEvent;
  102.   FDelphiControl.OnSelectCell := SelectCellEvent;
  103.   FDelphiControl.OnSetEditText := SetEditTextEvent;
  104.   FDelphiControl.OnTopLeftChanged := TopLeftChangedEvent;
  105. end;
  106.  
  107. procedure TDrawGridX.EventSinkChanged(const EventSink: IUnknown);
  108. begin
  109.   FEvents := EventSink as IDrawGridXEvents;
  110. end;
  111.  
  112. procedure TDrawGridX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  113. begin
  114.   { Define property pages here.  Property pages are defined by calling
  115.     DefinePropertyPage with the class id of the page.  For example,
  116.       DefinePropertyPage(Class_DrawGridXPage); }
  117. end;
  118.  
  119. function TDrawGridX.Get_Col: Integer;
  120. begin
  121.   Result := FDelphiControl.Col;
  122. end;
  123.  
  124. function TDrawGridX.Get_ColCount: Integer;
  125. begin
  126.   Result := FDelphiControl.ColCount;
  127. end;
  128.  
  129. function TDrawGridX.Get_Color: TColor;
  130. begin
  131.   Result := FDelphiControl.Color;
  132. end;
  133.  
  134. function TDrawGridX.Get_Ctl3D: WordBool;
  135. begin
  136.   Result := FDelphiControl.Ctl3D;
  137. end;
  138.  
  139. function TDrawGridX.Get_Cursor: Smallint;
  140. begin
  141.   Result := Smallint(FDelphiControl.Cursor);
  142. end;
  143.  
  144. function TDrawGridX.Get_DefaultColWidth: Integer;
  145. begin
  146.   Result := FDelphiControl.DefaultColWidth;
  147. end;
  148.  
  149. function TDrawGridX.Get_DefaultDrawing: WordBool;
  150. begin
  151.   Result := FDelphiControl.DefaultDrawing;
  152. end;
  153.  
  154. function TDrawGridX.Get_DefaultRowHeight: Integer;
  155. begin
  156.   Result := FDelphiControl.DefaultRowHeight;
  157. end;
  158.  
  159. function TDrawGridX.Get_DragCursor: Smallint;
  160. begin
  161.   Result := Smallint(FDelphiControl.DragCursor);
  162. end;
  163.  
  164. function TDrawGridX.Get_EditorMode: WordBool;
  165. begin
  166.   Result := FDelphiControl.EditorMode;
  167. end;
  168.  
  169. function TDrawGridX.Get_Enabled: WordBool;
  170. begin
  171.   Result := FDelphiControl.Enabled;
  172. end;
  173.  
  174. function TDrawGridX.Get_FixedColor: TColor;
  175. begin
  176.   Result := FDelphiControl.FixedColor;
  177. end;
  178.  
  179. function TDrawGridX.Get_FixedCols: Integer;
  180. begin
  181.   Result := FDelphiControl.FixedCols;
  182. end;
  183.  
  184. function TDrawGridX.Get_FixedRows: Integer;
  185. begin
  186.   Result := FDelphiControl.FixedRows;
  187. end;
  188.  
  189. function TDrawGridX.Get_Font: Font;
  190. begin
  191.   GetOleFont(FDelphiControl.Font, Result);
  192. end;
  193.  
  194. function TDrawGridX.Get_GridHeight: Integer;
  195. begin
  196.   Result := FDelphiControl.GridHeight;
  197. end;
  198.  
  199. function TDrawGridX.Get_GridLineWidth: Integer;
  200. begin
  201.   Result := FDelphiControl.GridLineWidth;
  202. end;
  203.  
  204. function TDrawGridX.Get_GridWidth: Integer;
  205. begin
  206.   Result := FDelphiControl.GridWidth;
  207. end;
  208.  
  209. function TDrawGridX.Get_LeftCol: Integer;
  210. begin
  211.   Result := FDelphiControl.LeftCol;
  212. end;
  213.  
  214. function TDrawGridX.Get_ParentColor: WordBool;
  215. begin
  216.   Result := FDelphiControl.ParentColor;
  217. end;
  218.  
  219. function TDrawGridX.Get_Row: Integer;
  220. begin
  221.   Result := FDelphiControl.Row;
  222. end;
  223.  
  224. function TDrawGridX.Get_RowCount: Integer;
  225. begin
  226.   Result := FDelphiControl.RowCount;
  227. end;
  228.  
  229. function TDrawGridX.Get_ScrollBars: TxScrollStyle;
  230. begin
  231.   Result := Ord(FDelphiControl.ScrollBars);
  232. end;
  233.  
  234. function TDrawGridX.Get_TopRow: Integer;
  235. begin
  236.   Result := FDelphiControl.TopRow;
  237. end;
  238.  
  239. function TDrawGridX.Get_Visible: WordBool;
  240. begin
  241.   Result := FDelphiControl.Visible;
  242. end;
  243.  
  244. function TDrawGridX.Get_VisibleColCount: Integer;
  245. begin
  246.   Result := FDelphiControl.VisibleColCount;
  247. end;
  248.  
  249. function TDrawGridX.Get_VisibleRowCount: Integer;
  250. begin
  251.   Result := FDelphiControl.VisibleRowCount;
  252. end;
  253.  
  254. procedure TDrawGridX.AboutBox;
  255. begin
  256.   ShowDrawGridXAbout;
  257. end;
  258.  
  259. procedure TDrawGridX.MouseToCell(X, Y: Integer; var ACol, ARow: Integer);
  260. begin
  261.  
  262. end;
  263.  
  264. procedure TDrawGridX.Set_Col(Value: Integer);
  265. begin
  266.   FDelphiControl.Col := Value;
  267. end;
  268.  
  269. procedure TDrawGridX.Set_ColCount(Value: Integer);
  270. begin
  271.   FDelphiControl.ColCount := Value;
  272. end;
  273.  
  274. procedure TDrawGridX.Set_Color(Value: TColor);
  275. begin
  276.   FDelphiControl.Color := Value;
  277. end;
  278.  
  279. procedure TDrawGridX.Set_Ctl3D(Value: WordBool);
  280. begin
  281.   FDelphiControl.Ctl3D := Value;
  282. end;
  283.  
  284. procedure TDrawGridX.Set_Cursor(Value: Smallint);
  285. begin
  286.   FDelphiControl.Cursor := TCursor(Value);
  287. end;
  288.  
  289. procedure TDrawGridX.Set_DefaultColWidth(Value: Integer);
  290. begin
  291.   FDelphiControl.DefaultColWidth := Value;
  292. end;
  293.  
  294. procedure TDrawGridX.Set_DefaultDrawing(Value: WordBool);
  295. begin
  296.   FDelphiControl.DefaultDrawing := Value;
  297. end;
  298.  
  299. procedure TDrawGridX.Set_DefaultRowHeight(Value: Integer);
  300. begin
  301.   FDelphiControl.DefaultRowHeight := Value;
  302. end;
  303.  
  304. procedure TDrawGridX.Set_DragCursor(Value: Smallint);
  305. begin
  306.   FDelphiControl.DragCursor := TCursor(Value);
  307. end;
  308.  
  309. procedure TDrawGridX.Set_EditorMode(Value: WordBool);
  310. begin
  311.   FDelphiControl.EditorMode := Value;
  312. end;
  313.  
  314. procedure TDrawGridX.Set_Enabled(Value: WordBool);
  315. begin
  316.   FDelphiControl.Enabled := Value;
  317. end;
  318.  
  319. procedure TDrawGridX.Set_FixedColor(Value: TColor);
  320. begin
  321.   FDelphiControl.FixedColor := Value;
  322. end;
  323.  
  324. procedure TDrawGridX.Set_FixedCols(Value: Integer);
  325. begin
  326.   FDelphiControl.FixedCols := Value;
  327. end;
  328.  
  329. procedure TDrawGridX.Set_FixedRows(Value: Integer);
  330. begin
  331.   FDelphiControl.FixedRows := Value;
  332. end;
  333.  
  334. procedure TDrawGridX.Set_Font(const Value: Font);
  335. begin
  336.   SetOleFont(FDelphiControl.Font, Value);
  337. end;
  338.  
  339. procedure TDrawGridX.Set_GridLineWidth(Value: Integer);
  340. begin
  341.   FDelphiControl.GridLineWidth := Value;
  342. end;
  343.  
  344. procedure TDrawGridX.Set_LeftCol(Value: Integer);
  345. begin
  346.   FDelphiControl.LeftCol := Value;
  347. end;
  348.  
  349. procedure TDrawGridX.Set_ParentColor(Value: WordBool);
  350. begin
  351.   FDelphiControl.ParentColor := Value;
  352. end;
  353.  
  354. procedure TDrawGridX.Set_Row(Value: Integer);
  355. begin
  356.   FDelphiControl.Row := Value;
  357. end;
  358.  
  359. procedure TDrawGridX.Set_RowCount(Value: Integer);
  360. begin
  361.   FDelphiControl.RowCount := Value;
  362. end;
  363.  
  364. procedure TDrawGridX.Set_ScrollBars(Value: TxScrollStyle);
  365. begin
  366.   FDelphiControl.ScrollBars := TScrollStyle(Value);
  367. end;
  368.  
  369. procedure TDrawGridX.Set_TopRow(Value: Integer);
  370. begin
  371.   FDelphiControl.TopRow := Value;
  372. end;
  373.  
  374. procedure TDrawGridX.Set_Visible(Value: WordBool);
  375. begin
  376.   FDelphiControl.Visible := Value;
  377. end;
  378.  
  379. procedure TDrawGridX.ClickEvent(Sender: TObject);
  380. begin
  381.   if FEvents <> nil then FEvents.OnClick;
  382. end;
  383.  
  384. procedure TDrawGridX.ColumnMovedEvent(Sender: TObject; FromIndex,
  385.   ToIndex: Integer);
  386. begin
  387.   if FEvents <> nil then FEvents.OnColumnMoved(FromIndex, ToIndex);
  388. end;
  389.  
  390. procedure TDrawGridX.DblClickEvent(Sender: TObject);
  391. begin
  392.   if FEvents <> nil then FEvents.OnDblClick;
  393. end;
  394.  
  395. procedure TDrawGridX.GetEditMaskEvent(Sender: TObject; ACol, ARow: Integer;
  396.   var Value: String);
  397. var
  398.   TempValue: WideString;
  399. begin
  400.   TempValue := WideString(Value);
  401.   if FEvents <> nil then FEvents.OnGetEditMask(ACol, ARow, TempValue);
  402.   Value := String(TempValue);
  403. end;
  404.  
  405. procedure TDrawGridX.GetEditTextEvent(Sender: TObject; ACol, ARow: Integer;
  406.   var Value: String);
  407. var
  408.   TempValue: WideString;
  409. begin
  410.   TempValue := WideString(Value);
  411.   if FEvents <> nil then FEvents.OnGetEditText(ACol, ARow, TempValue);
  412.   Value := String(TempValue);
  413. end;
  414.  
  415. procedure TDrawGridX.KeyPressEvent(Sender: TObject; var Key: Char);
  416. var
  417.   TempKey: Smallint;
  418. begin
  419.   TempKey := Smallint(Key);
  420.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  421.   Key := Char(TempKey);
  422. end;
  423.  
  424. procedure TDrawGridX.RowMovedEvent(Sender: TObject; FromIndex,
  425.   ToIndex: Integer);
  426. begin
  427.   if FEvents <> nil then FEvents.OnRowMoved(FromIndex, ToIndex);
  428. end;
  429.  
  430. procedure TDrawGridX.SelectCellEvent(Sender: TObject; Col, Row: Integer;
  431.   var CanSelect: Boolean);
  432. var
  433.   TempCanSelect: WordBool;
  434. begin
  435.   TempCanSelect := WordBool(CanSelect);
  436.   if FEvents <> nil then FEvents.OnSelectCell(Col, Row, TempCanSelect);
  437.   CanSelect := Boolean(TempCanSelect);
  438. end;
  439.  
  440. procedure TDrawGridX.SetEditTextEvent(Sender: TObject; ACol, ARow: Integer;
  441.   const Value: String);
  442. begin
  443.   if FEvents <> nil then FEvents.OnSetEditText(ACol, ARow, WideString(Value));
  444. end;
  445.  
  446. procedure TDrawGridX.TopLeftChangedEvent(Sender: TObject);
  447. begin
  448.   if FEvents <> nil then FEvents.OnTopLeftChanged;
  449. end;
  450.  
  451. initialization
  452.   TActiveXControlFactory.Create(
  453.     ComServer,
  454.     TDrawGridX,
  455.     TDrawGrid,
  456.     Class_DrawGridX,
  457.     7,
  458.     '{5A56597C-7975-11D0-BE02-00A024D1875C}');
  459. end.
  460.